package com.tsing.tsingfengmall.common.rest.vo;

import com.tsing.tsingfengmall.common.rest.exception.ResponseCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 统一返回结果实体类
 *
 * @author TheTsing
 */
@Getter
@Setter
@ToString
public class ResultData<T> {

    @Schema(description = "状态码")
    private int status;

    @Schema(description = "提示信息")
    private String msg;

    private T data;

    public static <T> ResultData<T> success() {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ResponseCode.SUCCESS.getCode());
        resultData.setMsg(ResponseCode.SUCCESS.getDescription());
        return resultData;
    }

    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(ResponseCode.SUCCESS.getCode());
        resultData.setMsg(ResponseCode.SUCCESS.getDescription());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> error(int code, String msg) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setStatus(code);
        resultData.setMsg(msg);
        return resultData;
    }

}
